// rev 11/05 11:48

#include <iostream>
#include <stdio.h>
#include <vector>
#include <stdlib.h>

namespace mzslam
{

template <class T>
class dgvector{
  std::vector<T> pos;
  std::vector<T> neg;

 public:
        
  dgvector(){
    pos = std::vector<T>();
    neg = std::vector<T>();
  }

  dgvector(int sizePos, int sizeNeg){
    pos = std::vector<T>(sizePos);
    neg = std::vector<T>(abs(sizeNeg));
  }

  void push_back(T add, int addToSign){
    if(addToSign >=0){
      pos.push_back(add);
    }
    else{
      neg.push_back(add);
    }
  }

  T& operator[](const int index){
    if(index >= 0){
      if((unsigned int)index > pos.size()){
	std::cout << "Out of range on pos! size is " << pos.size() << " input index is " << index << std::endl; 
      }
      return pos[index];
    }
    else{
      if(abs(index) > neg.size()){
	std::cout << "Out of range on neg! size is " << neg.size() << " input index - 1 is " << abs(index +1) << std::endl; 
      }
      return neg[abs(index + 1)];
    }
  }

  int size(){
    return pos.size();
  }

  int negsize(){
    return -neg.size();
  }

  void resize(int newSize){
    if(newSize >= 0){
      pos.resize(newSize + 1);
    }
    else{
      neg.resize(abs(newSize));
    }
  }

        

  void resizePos(int newSize){
    pos.resize(newSize);
  }

  void resizeNeg(int newSize){
    neg.resize(newSize);
  }

  void print(int min){
    if(neg.size() < abs(min)){
      for(int i = neg.size(); i < abs(min); i++){
	std::cout << "\t";
      }
    }
    for(int i = neg.size() -1; i >= 0 ;i--){
      std::cout << "\t" << neg[i];
    }
    for(unsigned int i = 0; i < pos.size();i++){
      std::cout << "\t" << pos[i];
    }
    std::cout << std::endl;
  }

  void print(){
    for(int i = -neg.size() +1; i <= 0;i++){
      std::cout << " " << neg[i];
    }
    for(int i = 0; i < pos.size();i++){
      std::cout << " " << pos[i];
    }
    std::cout << std::endl;
  }
};

} // end of namespace
